/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import entities.Authorisation;
import java.io.Serializable;

import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

public class UserTableModel extends ListDataModel<Authorisation> implements SelectableDataModel<Authorisation>, Serializable{

    public UserTableModel() {
    }

    public UserTableModel(List<Authorisation> data) {
        super(data);
    }

    @Override
    public Authorisation getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data

        List<Authorisation> users = (List<Authorisation>) getWrappedData();

        for(Authorisation user : users) {
            if(user.getUsername().equals(rowKey))
                return user;
        }

        return null;
    }

    @Override
    public Object getRowKey(Authorisation t) {
        return t.getUsername();
    }

}
